<template>
  <a-select
    v-on="$listeners"
    :options="lineOptions" :value.sync="$_value"
    placeholder="请选择线体" val-attr-name="LineId"/>
  <!--   @change="getStation"  -->
</template>

<script>
  import { getUserLineList } from '@/api/linebody'
  import ASelect from '@/components/ATheFridayClub/ASelect'
  import { getTechByTechId, getWorkStationInfo } from '@/api/scan'
  import { getBrowserInfo, getYourIP } from '@/utils/getIp'

  export default {
    name: 'LineSelect',
    components: { ASelect },
    props: {
      value: {
        type: [Number, String],
        require: true
      }
    },
    data() {
      return {
        lineOptions: []
      }
    },
    computed: {
      //  好烦琐,多次传值
      $_value: {
        get() {
          return this.value
        },
        set(newVal) {
          this.$emit('update:value', newVal)
        }
      }
    },
    created() {
      this.getLine()
    },
    methods: {
      genLabel(opts) {  //  新增了一个label的属性
        return opts.map(e => ({ ...e, label: `${e.LineId} - ${e.Name}` }))
      },
      //  获取线体,初始化
      getLine() {
        getUserLineList({ keyName: '', lineType: -1 }).then(res => {
          if (parseInt(res.Code) === 1) {
            this.lineOptions = this.genLabel(res.Result)
          }
        })
      },

      //  线体改变时触发的方法
      getStation(val) {

        // getYourIP();

        // console.log(getBrowserInfo())
        //获取本机电脑IP地址
        // var RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection
        //   || window.mozRTCPeerConnection
        // if (RTCPeerConnection) {
        //   (() => {
        //     var rtc = new RTCPeerConnection()
        //     rtc.createDataChannel('')//创建一个可以发送任意数据的数据通道
        //     rtc.createOffer(offerDesc => {  //创建并存储一条sdp数据
        //       rtc.setLocalDescription(offerDesc)
        //     }, e => {
        //     })
        //     rtc.onicecandidate = (evt) => {   //监听candidate事件
        //       // console.log(evt)
        //       if (evt.candidate && evt.candidate.foundation == 25531464) {
        //         var ip_addr = evt.candidate.address
        //         console.log(this.ip_addr)
        //         localStorage.setItem('ip_addr', ip_addr)
        //       }
        //     }
        //   })()
        // }

        // console.log(localStorage.getItem('ip_addr'))

        // var ipaddress = localStorage.getItem('ip_addr')
        // //通过电脑IP地址获取当前工位信息
        // getWorkStationInfo({ ipAddress: ipaddress, techType: 0, lineId: parseInt(this.lineId) }).then(res => {
        //   if (parseInt(res.Code) === 1) {
        //     this.workStationData = res.Result
        //     getTechByTechId({ techId: parseInt(this.workStationData.TechId) }).then(res => {
        //       if (parseInt(res.Code) === 1) {
        //         this.photoData = res.Result.TechGuides
        //       }
        //     }).catch(res => {
        //     })
        //   }
        // }).catch(res => {
        // })

      }

    }
  }
</script>

<style lang="scss" scoped>

</style>
